﻿using Fur.DependencyInjection;
using System;
using System.Reflection;

namespace Fur.Application.Aop.Services
{
    public class LogDispatchProxy : DispatchProxy, IDispatchProxy
    {
        /// <summary>
        /// 当前服务实例
        /// </summary>
        public object Target { get; set; }

        /// <summary>
        /// 服务提供器，可以用来解析服务，如：ServiceProvider.GetService()
        /// </summary>
        public IServiceProvider ServiceProvider { get; set; }

        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            Console.WriteLine($"{targetMethod.Name} 方法被调用了");

            var result = targetMethod.Invoke(Target, args);

            Console.WriteLine($"{targetMethod.Name} 方法返回值：" + result);

            return result;
        }
    }
}
